package com.css.dzj.dzjap.modules.export.controller;

import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjap.common.util.R;
import com.css.dzj.dzjap.modules.export.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(value = "/import")
public class ImportController {

    @Autowired
    private ImportService importService;
    @Autowired
    BaseService baseService;
    @PostMapping("/expertImport")
    public R expertImport(@RequestParam("file") MultipartFile file){
     try {
         String flag = importService.expertImport(file);
         if (!"0".equals(flag)) {
             R r = new R();
             r.put("code", 200);
             r.put("msg", "操作成功");
             r.ok().put("data", flag);
             baseService.logSuccess(3,"导入成功","2");
             return r;
         } else {
             baseService.logFailed(3,"导入失败","2");
             return R.error("导入失败");
         }
     }catch (Exception e){
         baseService.logFailed(3,"导入失败","2");
         return  R.error(e.getMessage());
     }

    }

}
